﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//.............
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//...................
namespace QLKTX1._0.DAO
{
    class LoaiChiPhiDAO
    {
        public static List<LoaiChiPhiDTO> dsLoaiChiPhi()
        {
            List<LoaiChiPhiDTO> dsLoaiChiPhi = new List<LoaiChiPhiDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM loaiChiPhi");
            for (int i = 0; i < dt.Rows.Count;i++ )
            {
                LoaiChiPhiDTO loaiChiPhi = new LoaiChiPhiDTO();
                loaiChiPhi.MaLoaiChiPhi = dt.Rows[i]["maLoai_chiPhi"].ToString();
                loaiChiPhi.TenLoaiChiPhi = dt.Rows[i]["tenLoai_chiPhi"].ToString();
                loaiChiPhi.DonViTinh = dt.Rows[i]["donViTinh"].ToString();
                dsLoaiChiPhi.Add(loaiChiPhi);
            }
            return dsLoaiChiPhi;
        }
        // Ham Insert 
        public static bool themLoaiChiPhi(LoaiChiPhiDTO loaiChiPhi)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO loaiChiPhi(maLoai_chiPhi,tenLoai_chiPhi,donViTinh) VALUES('" + loaiChiPhi .MaLoaiChiPhi  + "','" + loaiChiPhi .TenLoaiChiPhi  + "','"+ loaiChiPhi .DonViTinh +"')");

        }
        //Ham delete
        public static bool xoaLoaiChiPhi(LoaiChiPhiDTO loaiChiPhi)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM loaiChiPhi WHERE maLoai_chiPhi='" + loaiChiPhi.MaLoaiChiPhi + "'");
        }
        //ham update
        public static bool capNhatLoaiChiPhi(LoaiChiPhiDTO loaiChiPhi)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE loaiChiPhi set tenLoai_chiPhi='" + loaiChiPhi.TenLoaiChiPhi + "',donViTinh='"+ loaiChiPhi .DonViTinh +"' WHERE maLoai_chiPhi='" + loaiChiPhi.MaLoaiChiPhi + "'");
        }
    }
}
